home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / pichrt10 / pie_test / pie_form.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  1.9 KB  |  80 lines

  1. unit pie_form;
  2.  
  3. // simple program to test and demonstrator the PieChart unit
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  9.   StdCtrls, PieChart;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     ListBox1: TListBox;
  14.     PieChart1: TPieChart;
  15.     ListBox2: TListBox;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure PieChart1DblClick(Sender: TObject);
  18.     procedure ListBox1DblClick(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure TForm1.FormCreate(Sender: TObject);
  33. var
  34.   str: TStringList;
  35.   i: integer;
  36. begin
  37.   str := TStringList.Create;
  38.   with ListBox2.Items do
  39.     begin
  40.     for i := 0 to Count-1 do
  41.       // Add the string, and an object.  Here the object is just
  42.       // an integer used to record the index of the string in the
  43.       // list box.  It is type-cast into an object (pointer).
  44.       str.AddObject (Strings [i], pointer (i));
  45.     end;
  46.   PieChart1.SetDataAndLabels (str);
  47.   str.Free;
  48. end;
  49.  
  50. procedure TForm1.PieChart1DblClick(Sender: TObject);
  51. var
  52.   i: integer;
  53. begin
  54.   // Convert object pointer back to usefule information, here the index
  55.   // into a TStrings object attached to a list box.  Note that the full
  56.   // string as stored is displayed, including the number part
  57.   i := integer(PieChart1.ClickedObject);
  58.   ShowMessage (ListBox2.Items.strings [i]);
  59. end;
  60.  
  61. procedure TForm1.ListBox1DblClick(Sender: TObject);
  62. var
  63.   s: string;
  64.   space: integer;
  65. begin
  66.   // if the list box is doubled clicked, find the item currently
  67.   // selected (i.e. at ItemIndex), and remove any numeric part
  68.   with ListBox1 do
  69.     begin
  70.     s := Items [ItemIndex];
  71.     space := Pos (' ', s);
  72.     if space = 0
  73.     then s := ''
  74.     else s := Trim (Copy (s, space, 999));
  75.     ShowMessage (s);
  76.     end;
  77. end;
  78.  
  79. end.
  80.